using System;

namespace DotNetNukeMVPWizard.ProjectConfiguration
{
    public class FolderPathConfiguration : TextConfiguration
    {
        #region Constructors
        public FolderPathConfiguration(string key)
            : base(key)
        {
        }

        public FolderPathConfiguration(string key, string errorReason)
            : base(key, errorReason)
        {
        }
        public FolderPathConfiguration(string key, string errorReason, bool isOptional)
            : base(key, errorReason, isOptional)
        {
        }
         
        #endregion

        #region Property Overrides
        public override string Value
        {
            get { return base.Value; }
            set
            {
                if (!string.IsNullOrEmpty(value) && !value.EndsWith(@"\"))
                    value += @"\";
                base.Value = value;
            }
        }

        public override bool IsValid
        {
            get
            {
                bool _isValid = true;
                _isValid = (IsOptional && string.IsNullOrEmpty(Value)) || System.IO.Directory.Exists(Value);
                return _isValid;
            }
        }
        #endregion
    }
}
